11---
2- title : ' Working with branches and remotes '
2+ title : ' Working with branches'
33description : ' Most projects have a complicated history that is not a straight line and include contributions from multiple people'
4- order : 5
4+ order : 6
55state : ' upcoming'
66tags : ['git']
77links : {
88 ' Git Branching Documentation ' : ' https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell' ,
99 ' Interactive Git Branching ' : ' https://learngitbranching.js.org/' ,
10- ' Referencing commits docs ' : ' https://git-scm.com/docs/gitrevisions' ,
1110}
1211---
1312
14- ## Short recap
15-
16- - Git commands are local-first
17-
18- - Commit often and write good commit messages
19-
20- - Be careful with commands that can permanently delete files
21-
22- ---
23-
2413## What Are Branches?
2514
2615A ** branch** in Git is essentially a moveable pointer to a specific commit.
@@ -42,6 +31,7 @@ Branches are incredibly lightweight - creating a branch is just creating a file
4231---
4332
4433## Listing Branches
34+
4535When you create a repository, Git automatically creates a default branch (usually called ` main ` or ` master ` ).
4636
4737``` bash
9686john-branch
9787new-feature
9888```
89+
9990---
10091
10192## Switching Between Branches
@@ -209,21 +200,6 @@ git log --oneline --graph master...experimental
209200
210201---
211202
212- ## Referencing commits
213-
214- There are many ways to get to a commit.
215- ![ example-history] ( https://git-scm.com/book/en/v2/images/double-dot.png )
216-
217- ``` bash
218- master^ # E
219- master~2 # B
220- B^ # A
221- B~1 # A
222- ^B # everything except A and B
223- ```
224-
225- ---
226-
227203## Detached HEAD
228204
229205If HEAD points directly at a commit, git will inform you that
@@ -285,139 +261,12 @@ ls
285261
286262### Feature Branch Workflow
287263
288- 1 . Create a repository with a README
289- 2 . Create three feature branches: ` feature-header ` , ` feature-footer ` , ` feature-sidebar `
264+ 1 . Create a repository called 'my-site'
265+ 2 . Add a README file
266+ 2 . Create three branches: ` feature-header ` , ` feature-footer ` , ` feature-sidebar `
2902673 . Make different changes in each branch
2912684 . Practice viewing the history with ` git log --graph --oneline `
292269
293270</home-work >
294271
295272</bonus-content >
296-
297- ---
298-
299- ## Remote Repositories
300-
301- A ** remote repository** is a independent version of the project hosted somewhere else (like GitHub, GitLab, or Bitbucket).
302-
303- It enables collaboration and serves as a backup.
304-
305- ---
306-
307- ### Local vs Remote
308-
309- ![ remote-example] ( https://git-scm.com/book/en/v2/images/remote-branches-1.png )
310-
311- ---
312-
313- ### Common Remote Hosting Services
314-
315- - ** GitHub** - Most popular, great for open source
316- - ** GitLab** - Good for enterprise, built-in CI/CD
317- - ** Bitbucket** - Integrates well with Atlassian tools
318- - ** Azure DevOps** - Microsoft's solution
319- - ** Self-hosted** - Your own server
320-
321- ---
322-
323- ## Adding a Remote
324-
325- ``` bash
326- # Add a remote repository
327- git remote add origin https://github.com/user/repo.git
328-
329- # List remotes
330- git remote -v
331-
332- # Show detailed remote info
333- git remote show origin
334- ```
335-
336- ---
337-
338- ### Common Remote Names
339-
340- - ** origin** - Default name for the remote repository that was cloned
341- - ** upstream** - Often used for the original repository when you've forked
342- - ** fork** - Sometimes used for your fork of someone else's repository
343-
344- > Remote names are local, choose names that make sense for you.
345-
346- ---
347-
348- ## Fetching and Pulling
349-
350- ``` bash
351- # Download changes without merging
352- git fetch origin
353-
354- # Download and merge changes
355- git pull origin main
356-
357- # Pull with rebase instead of merge
358- git pull --rebase origin main
359- ```
360-
361- ---
362-
363- ## Pushing to Remote
364-
365- ``` bash
366- # Push current branch to remote
367- git push origin main
368-
369- # Push and set upstream tracking
370- git push -u origin feature-branch
371-
372- # Push all branches
373- git push origin --all
374-
375- # Push tags
376- git push origin --tags
377- ```
378-
379- ---
380-
381- ## Tracking Remote Branches
382-
383- ``` bash
384- # See all branches (local and remote)
385- git branch -a
386-
387- # Create local branch that tracks remote
388- git checkout -b feature-branch origin/feature-branch
389-
390- # Simplified version (Git 2.23+)
391- git switch feature-branch # Auto-tracks if remote exists
392- ```
393-
394- ---
395-
396- ## Working with Remote Branches
397-
398- ``` bash
399- # Create local branch
400- git checkout -b new-feature
401-
402- # make changes, commit and push to remote
403- git push -u origin new-feature
404-
405- # Delete remote branch
406- git push origin --delete old-feature
407-
408- # Update remote tracking branches
409- git fetch --prune
410- ```
411-
412- ---
413-
414- ## Branch Lifecycle
415-
416- 1 . ** Create** branch from up-to-date main
417- 2 . ** Work** on feature with regular commits
418- 3 . ** Test** thoroughly before merging
419- 4 . ** Request** code review
420- 5 . ** Merge** to main after approval
421- 6 . ** Delete** feature branch after merge
422- 7 . ** Update** local main branch
423-
0 commit comments