<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki-ext.aps.anl.gov/blc/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rodolakis</id>
	<title>Beam Line Controls - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki-ext.aps.anl.gov/blc/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rodolakis"/>
	<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Special:Contributions/Rodolakis"/>
	<updated>2026-06-04T11:51:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=793</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=793"/>
		<updated>2024-08-08T18:16:02Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitLab */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (i.e. your own GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project (e.g. beamline software). &lt;br /&gt;
* The naming convention recommended for a given beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
GitLab is typically used for internal project (e.g. IOCs, UI screens...). APS hosts its own GitLab service: https://git.aps.anl.gov. Contact your IT contact to get access.&lt;br /&gt;
* GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=792</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=792"/>
		<updated>2024-08-08T18:14:35Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub vs GitLab: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (i.e. your own GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project (e.g. beamline software). &lt;br /&gt;
* The naming convention recommended for a given beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
GitLab is typically used for internal project (e.g. IOCs, UI screens...). APS hosts its own GitLab service: https://git.aps.anl.gov. Contact your IT contact to get access.&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=791</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=791"/>
		<updated>2024-08-08T18:10:55Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub vs GitLab: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (i.e. your own GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project (e.g. beamline software). &lt;br /&gt;
* The naming convention recommended for a given beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=790</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=790"/>
		<updated>2024-08-08T18:10:34Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (i.e. your own GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project (e.g. beamline software). &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=789</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=789"/>
		<updated>2024-08-08T18:09:45Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub vs GitLab: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (i.e. your own GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=788</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=788"/>
		<updated>2024-08-08T18:09:15Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub vs GitLab: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (i.e. your own GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=787</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=787"/>
		<updated>2024-08-08T18:08:58Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (*your* GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=786</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=786"/>
		<updated>2024-08-08T18:08:47Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (**your** GitHub account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=785</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=785"/>
		<updated>2024-08-08T18:07:49Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitHub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (your github account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=784</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=784"/>
		<updated>2024-08-08T18:07:13Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Putting a new project/folder under version control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
===== GitHub =====&lt;br /&gt;
&lt;br /&gt;
GitHub https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
* GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (your github account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
* BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
* It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
* The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
&lt;br /&gt;
===== GitLab =====&lt;br /&gt;
&lt;br /&gt;
APS's GitLab (https://git.aps.anl.gov) is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
* APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
* BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
* It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=783</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=783"/>
		<updated>2024-08-08T18:05:37Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitLab vs GitHub: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitHub vs GitLab: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
* GitHub: https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
** GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account (your github account) or a named organization (e.g. BCDA-APS or APS-29IDC-MM).&lt;br /&gt;
** BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
** It is recommended to use an organization vs individual account to host shared project. &lt;br /&gt;
** The naming convention recommended for the beamline organization is: APS-SSS-GGG&lt;br /&gt;
*** SSS: sector, beamline, and station, if relevant (e.g. 29IDC)&lt;br /&gt;
*** GGG: operating group (e.g. MM for XSD - Magnetic Material)&lt;br /&gt;
&lt;br /&gt;
* GitLab: https://git.aps.anl.gov is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
** APS GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
** BCDA maintains group for each beamline; ask your BCDA contact to be added to your beamline group.&lt;br /&gt;
** It is recommended to use your beamline group vs individual account to host shared project (individual accounts are deleted when employee leave the lab).&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=782</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=782"/>
		<updated>2024-08-08T17:54:42Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitLab vs GitHub: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitLab vs GitHub: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
* GitLab: https://git.aps.anl.gov is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
** GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
** BCDA maintains group for each beamline; ask your beamline contact to be added to your beamline group.&lt;br /&gt;
* GitHub: https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
** GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY, where &amp;quot;ORGANIZATION&amp;quot; is either a single user account or a named organization.&lt;br /&gt;
** BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=781</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=781"/>
		<updated>2024-08-08T17:54:27Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitLab vs GitHub: What should I use? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitLab vs GitHub: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
* GitLab: https://git.aps.anl.gov is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
** GitLab organizes repositories using this pattern: https://git.aps.anl.gov/GROUP/REPOSITORY&lt;br /&gt;
** BCDA maintains group for each beamline; ask your beamline contact to be added to your beamline group.&lt;br /&gt;
* GitHub: https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
** GitHub organizes repositories using this pattern: https://github.com/ORGANIZATION/REPOSITORY&lt;br /&gt;
where &amp;quot;ORGANIZATION&amp;quot; is either a single user account or a named organization.&lt;br /&gt;
** BCDA organization: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=780</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=780"/>
		<updated>2024-08-08T16:06:31Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* GitLab vs GitHub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitLab vs GitHub: What should I use? ====&lt;br /&gt;
&lt;br /&gt;
* GitLab: https://git.aps.anl.gov is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
  * BCDA maintains sector &amp;quot;groups&amp;quot; &lt;br /&gt;
* GitHub: https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
  * Note that BCDA has his own &amp;quot;organization&amp;quot; on GitHub: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=779</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=779"/>
		<updated>2024-08-08T16:05:17Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Putting a new project/folder under version control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
==== GitLab vs GitHub ====&lt;br /&gt;
&lt;br /&gt;
* GitLab: https://git.aps.anl.gov is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
  * BCDA maintains sector &amp;quot;groups&amp;quot; &lt;br /&gt;
* GitHub: https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
  * BCDA has his own organization on GitHub: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
==== Example on GitLab ====&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs, i.e. GitLab (steps are the same on GitHub). For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=778</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=778"/>
		<updated>2024-08-08T16:02:27Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Putting a new project/folder under version control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
GitLab vs GitHub - best practices:&lt;br /&gt;
&lt;br /&gt;
* GitLab: https://git.aps.anl.gov is typically used for internal project (e.g. IOCs, UI screens...)&lt;br /&gt;
  * BCDA maintains sector &amp;quot;groups&amp;quot; &lt;br /&gt;
* GitHub: https://github.com is typically used for public project, to be shared accros user facilities or with the users themselves (e.g. apstools, MDA_Utilities...)&lt;br /&gt;
  * BCDA has his own organization on GitHub: https://github.com/BCDA-APS&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs. For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=756</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=756"/>
		<updated>2024-02-18T15:24:44Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Putting a new folder under version control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new project/folder under version control ===&lt;br /&gt;
&lt;br /&gt;
This section uses the example of an EPICS IOCs. For a different type of project, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=755</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=755"/>
		<updated>2024-02-18T15:24:08Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Version Control for EPICS IOCs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Putting a new folder under version control ===&lt;br /&gt;
&lt;br /&gt;
THis use the example of an EPICS IOCs. For a different project/folder, just skip the reference to `xxx` (first 2 lines in the repo initialization).&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Beamline_Controls&amp;diff=754</id>
		<title>Beamline Controls</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Beamline_Controls&amp;diff=754"/>
		<updated>2024-02-01T00:34:27Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WIKI for the APS Beamline Controls Community, maintained by the Beamline Controls Technical Working Group.&amp;lt;br /&amp;gt;&lt;br /&gt;
This wiki exists to collect the output of the working group, including documentation on beamline controls software and hardware useful for APS beamline scientists and resident users.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Getting Started===&lt;br /&gt;
* [[EPICS Cheat Sheet]]: Channel Access command-lines, noteworthy record fields &amp;amp; IOC shell commands.&lt;br /&gt;
* [[EPICS 101]]: definition of basic EPICS components ([[EPICS_101#What_is_an_IOC.3F|IOC]], [[EPICS 101#What_is_a_PV.3F|PV]], [[EPICS_101#What_is_a_record.3F|record]], [[EPICS 101#What_is_a_database.3F|database]]).&lt;br /&gt;
* [[IOC 101]]: learn how to create your own IOC.&lt;br /&gt;
* [[Git_101|Git 101]]: git refresher (basic workflow, commands, and more).&lt;br /&gt;
&lt;br /&gt;
===Beamline Controls Documentation===&lt;br /&gt;
&lt;br /&gt;
* [[EPICS networking]]: basic overview of how to control the network paths used by EPICS IOCs and clients.&lt;br /&gt;
* [[Controls Software Documentation]]&lt;br /&gt;
* [[Hardware and IT Configuration]]&lt;br /&gt;
&lt;br /&gt;
===Practical Beamline Controls Training (2023)===&lt;br /&gt;
&lt;br /&gt;
[[Practical_Beamline_Controls_Training#IOC_Basics|Session 1: IOC Basics]]&lt;br /&gt;
[[Practical_Beamline_Controls_Training#IOC_Deployment_.26_Troubleshooting|Session 2: IOC Deployment &amp;amp; Troubleshooting]]&lt;br /&gt;
&lt;br /&gt;
===Beamline Controls Technical Working Group information===&lt;br /&gt;
&lt;br /&gt;
The BC Technical Working (BCTWG) group meets monthly to review and gather feedback on possible changes in either the way BC delivers support or the technologies that BC supports. The BCTWG comprises the BC group plus interested stakeholders from XSD. In a nutshell, the main goal of the BCTWG is to improve communication between BC and its customers on topics of mutual interest.&lt;br /&gt;
&lt;br /&gt;
* Box folder with slides and meeting notes (ANL only): [https://anl.box.com/s/chcn7xauil93inay8ipinbxtcckc9k9f]&lt;br /&gt;
&lt;br /&gt;
* Current chairs:&lt;br /&gt;
** Kevin Peterson (XSD-BC)&lt;br /&gt;
** Tejas Guruswamy (XSD-DET)&lt;br /&gt;
** Andrew Chuang (XSD-MPE)&lt;br /&gt;
&lt;br /&gt;
===Beamline Data Pipelines===&lt;br /&gt;
&lt;br /&gt;
* https://git.aps.anl.gov/groups/bdp-public/-/wikis/home&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Beamline_Controls&amp;diff=753</id>
		<title>Beamline Controls</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Beamline_Controls&amp;diff=753"/>
		<updated>2024-02-01T00:34:15Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WIKI for the APS Beamline Controls Community, maintained by the Beamline Controls Technical Working Group.&amp;lt;br /&amp;gt;&lt;br /&gt;
This wiki exists to collect the output of the working group, including documentation on beamline controls software and hardware useful for APS beamline scientists and resident users.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Getting Started===&lt;br /&gt;
* [[EPICS Cheat Sheet]]: Channel Access command-lines, noteworthy record fields &amp;amp; IOC shell commands.&lt;br /&gt;
* [[EPICS 101]]: definition of basic EPICS components ([[EPICS_101#What_is_an_IOC.3F|IOC]], [[EPICS 101#What_is_a_PV.3F|PV]], [[EPICS_101#What_is_a_record.3F|record]], [[EPICS 101#What_is_a_database.3F|database]]).&lt;br /&gt;
* [[IOC 101]]: learn how to create your own IOC.&lt;br /&gt;
* [[Git_101|Git 101]]: git refresher (basic workflow, commands, and more)&lt;br /&gt;
&lt;br /&gt;
===Beamline Controls Documentation===&lt;br /&gt;
&lt;br /&gt;
* [[EPICS networking]]: basic overview of how to control the network paths used by EPICS IOCs and clients.&lt;br /&gt;
* [[Controls Software Documentation]]&lt;br /&gt;
* [[Hardware and IT Configuration]]&lt;br /&gt;
&lt;br /&gt;
===Practical Beamline Controls Training (2023)===&lt;br /&gt;
&lt;br /&gt;
[[Practical_Beamline_Controls_Training#IOC_Basics|Session 1: IOC Basics]]&lt;br /&gt;
[[Practical_Beamline_Controls_Training#IOC_Deployment_.26_Troubleshooting|Session 2: IOC Deployment &amp;amp; Troubleshooting]]&lt;br /&gt;
&lt;br /&gt;
===Beamline Controls Technical Working Group information===&lt;br /&gt;
&lt;br /&gt;
The BC Technical Working (BCTWG) group meets monthly to review and gather feedback on possible changes in either the way BC delivers support or the technologies that BC supports. The BCTWG comprises the BC group plus interested stakeholders from XSD. In a nutshell, the main goal of the BCTWG is to improve communication between BC and its customers on topics of mutual interest.&lt;br /&gt;
&lt;br /&gt;
* Box folder with slides and meeting notes (ANL only): [https://anl.box.com/s/chcn7xauil93inay8ipinbxtcckc9k9f]&lt;br /&gt;
&lt;br /&gt;
* Current chairs:&lt;br /&gt;
** Kevin Peterson (XSD-BC)&lt;br /&gt;
** Tejas Guruswamy (XSD-DET)&lt;br /&gt;
** Andrew Chuang (XSD-MPE)&lt;br /&gt;
&lt;br /&gt;
===Beamline Data Pipelines===&lt;br /&gt;
&lt;br /&gt;
* https://git.aps.anl.gov/groups/bdp-public/-/wikis/home&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Beamline_Controls&amp;diff=752</id>
		<title>Beamline Controls</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Beamline_Controls&amp;diff=752"/>
		<updated>2024-02-01T00:33:40Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;WIKI for the APS Beamline Controls Community, maintained by the Beamline Controls Technical Working Group.&amp;lt;br /&amp;gt;&lt;br /&gt;
This wiki exists to collect the output of the working group, including documentation on beamline controls software and hardware useful for APS beamline scientists and resident users.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Getting Started===&lt;br /&gt;
* [[EPICS Cheat Sheet]]: Channel Access command-lines, noteworthy record fields &amp;amp; IOC shell commands.&lt;br /&gt;
* [[EPICS 101]]: definition of basic EPICS components ([[EPICS_101#What_is_an_IOC.3F|IOC]], [[EPICS 101#What_is_a_PV.3F|PV]], [[EPICS_101#What_is_a_record.3F|record]], [[EPICS 101#What_is_a_database.3F|database]]).&lt;br /&gt;
* [[IOC 101]]: learn how to create your own IOC.&lt;br /&gt;
* [[Git_101|Git 101]]&lt;br /&gt;
&lt;br /&gt;
===Beamline Controls Documentation===&lt;br /&gt;
&lt;br /&gt;
* [[EPICS networking]]: basic overview of how to control the network paths used by EPICS IOCs and clients.&lt;br /&gt;
* [[Controls Software Documentation]]&lt;br /&gt;
* [[Hardware and IT Configuration]]&lt;br /&gt;
&lt;br /&gt;
===Practical Beamline Controls Training (2023)===&lt;br /&gt;
&lt;br /&gt;
[[Practical_Beamline_Controls_Training#IOC_Basics|Session 1: IOC Basics]]&lt;br /&gt;
[[Practical_Beamline_Controls_Training#IOC_Deployment_.26_Troubleshooting|Session 2: IOC Deployment &amp;amp; Troubleshooting]]&lt;br /&gt;
&lt;br /&gt;
===Beamline Controls Technical Working Group information===&lt;br /&gt;
&lt;br /&gt;
The BC Technical Working (BCTWG) group meets monthly to review and gather feedback on possible changes in either the way BC delivers support or the technologies that BC supports. The BCTWG comprises the BC group plus interested stakeholders from XSD. In a nutshell, the main goal of the BCTWG is to improve communication between BC and its customers on topics of mutual interest.&lt;br /&gt;
&lt;br /&gt;
* Box folder with slides and meeting notes (ANL only): [https://anl.box.com/s/chcn7xauil93inay8ipinbxtcckc9k9f]&lt;br /&gt;
&lt;br /&gt;
* Current chairs:&lt;br /&gt;
** Kevin Peterson (XSD-BC)&lt;br /&gt;
** Tejas Guruswamy (XSD-DET)&lt;br /&gt;
** Andrew Chuang (XSD-MPE)&lt;br /&gt;
&lt;br /&gt;
===Beamline Data Pipelines===&lt;br /&gt;
&lt;br /&gt;
* https://git.aps.anl.gov/groups/bdp-public/-/wikis/home&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=751</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=751"/>
		<updated>2024-02-01T00:31:01Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Version Control for EPICS IOCs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see [[#Why clone with SSH URL|Why clone with SSH URL]].&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=750</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=750"/>
		<updated>2024-02-01T00:26:59Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Version Control for EPICS IOCs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
Note: see Why clone with SSH URL&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=749</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=749"/>
		<updated>2024-02-01T00:25:38Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Upstream Branch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Choosing a URL for your remote repository ===&lt;br /&gt;
&lt;br /&gt;
==== Why clone with SSH URL ====&lt;br /&gt;
&lt;br /&gt;
Github support for password authentication (HTTPS) was removed on August 13, 2021. SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and  [https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account add the public key to your account on GitHub.com]&lt;br /&gt;
&lt;br /&gt;
If you cloned your repository using the HTTP URL, you can switch to SSH at any time:&lt;br /&gt;
&lt;br /&gt;
 git remote -v  # check the current repo url&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (fetch)&lt;br /&gt;
    origin  https://github.com/BCDA-APS/myrepo (push)&lt;br /&gt;
 git remote set-url origin git@github.com:BCDA-APS/myrepo.git&lt;br /&gt;
 git remote -v  # verify the changes to the new url&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (fetch)&lt;br /&gt;
    origin  git@github.com:BCDA-APS/myrepo.git (push)&lt;br /&gt;
&lt;br /&gt;
==== More details about HHTPS vs SSH ====&lt;br /&gt;
&lt;br /&gt;
* HTTPS (Hypertext Transfer Protocol Secure):&lt;br /&gt;
** Ease of Use: Generally easier for beginners to set up and use, as it often works out of the box without any additional configuration.&lt;br /&gt;
** Authentication: Uses username and password for authentication. This can be less convenient because you might need to enter your credentials frequently unless you use a credential helper.&lt;br /&gt;
** Security: Secure, as it encrypts the data transferred over the network.&lt;br /&gt;
&lt;br /&gt;
* SSH (Secure Shell):&lt;br /&gt;
** Ease of Use: Requires a bit more setup initially. You need to generate an SSH key pair and add the public key to your GitHub account.&lt;br /&gt;
** Authentication: Uses key-based authentication. This is more secure and convenient once set up, as you don’t have to enter your username and password regularly.&lt;br /&gt;
** Security: Highly secure, with strong encryption of data. The key-based authentication is generally considered more robust than password-based authentication.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=748</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=748"/>
		<updated>2024-01-19T00:38:16Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Version Control for EPICS IOCs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Code drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=747</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=747"/>
		<updated>2024-01-18T23:06:17Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Branching for IOCs Upgrade */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
This is an example for upgrading from 6.1 to 6.2:&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=740</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=740"/>
		<updated>2023-12-20T00:51:45Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Custom aliases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png|thumb|center|900px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=739</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=739"/>
		<updated>2023-12-20T00:51:18Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Custom aliases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits:&lt;br /&gt;
&lt;br /&gt;
[[File:git_lg.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=File:Git_lg.png&amp;diff=738</id>
		<title>File:Git lg.png</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=File:Git_lg.png&amp;diff=738"/>
		<updated>2023-12-20T00:50:17Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=IOC_101&amp;diff=737</id>
		<title>IOC 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=IOC_101&amp;diff=737"/>
		<updated>2023-12-08T22:54:34Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* What's next? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
== What is an IOC ==&lt;br /&gt;
&lt;br /&gt;
For a basic description, see [https://wiki-ext.aps.anl.gov/blc/index.php?title=EPICS_101#What_is_an_IOC.3F Epics 101]&lt;br /&gt;
[[File:EPICS_basics_PV_diagram.png|right|thumb|700px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== How does one create an IOC? ==&lt;br /&gt;
&lt;br /&gt;
There are multiple ways to create an IOC, but no one does it from scratch:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The EPICS base approach ===&lt;br /&gt;
&lt;br /&gt;
Not recommended: it creates a bare bones IOC but requires more knowledge of the EPICS build system to get started:&lt;br /&gt;
::'''&amp;lt;code&amp;gt;makeBaseApp.pl&amp;lt;/code&amp;gt;'''&lt;br /&gt;
* Must be run multiple times&lt;br /&gt;
* Creates IOC contents in the current directory&lt;br /&gt;
* synApps support needs to be added manually&lt;br /&gt;
&lt;br /&gt;
=== The synApps approach ===&lt;br /&gt;
&lt;br /&gt;
It is based on the ''xxx'' module and designed to give you a usable IOC with as little effort as possible:&lt;br /&gt;
:::'''&amp;lt;code&amp;gt;/APSshare/bin/mkioc&amp;lt;/code&amp;gt;'''&lt;br /&gt;
 &lt;br /&gt;
* A single command leaves you with an IOC you can build:&lt;br /&gt;
&lt;br /&gt;
 $/APSshare/bin/mkioc -n -f -s 6-2-1 kmp&lt;br /&gt;
 &lt;br /&gt;
 Usage: mkioc [options] ioc_name&lt;br /&gt;
 -h            print this message&lt;br /&gt;
 -v            print the version&lt;br /&gt;
 -f            create a fresh git repo without an xxx remote&lt;br /&gt;
 -g            default to creating gitlab repo and pushing ioc&lt;br /&gt;
 -n            default to not creating gitlab repo and pushing ioc&lt;br /&gt;
 -s &amp;lt;version&amp;gt;  use a specific synApps version&lt;br /&gt;
&lt;br /&gt;
* Creates a top-level IOC directory in the current directory&lt;br /&gt;
* Common synApps support is included by default (common records/modules such as '''alive''', '''sscan''', '''calc'''...) &lt;br /&gt;
* '''&amp;lt;code&amp;gt;mkioc&amp;lt;/code&amp;gt;''' will ask you questions if you run it without options&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: The BCDA convention is to name development IOCs using the developer's initials (here we will use either ''xxx'' or ''kmp'').&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== IOC Layout ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The IOC layout can be overwhelming and confusing to those who aren’t yet familiar with it. The EPICS build system creates many directories, making it harder to find the important directories.&lt;br /&gt;
Important files are often buried multiple directories down from the top-level. It is helpful to look at subsets of the IOC directory. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: &lt;br /&gt;
* '''build''': building an IOC is the action of compiling i.e. generating the binary &amp;lt;code&amp;gt;bin/rhel#-x86_64/xxxApp&amp;lt;/code&amp;gt; (plus other build products as described below) by using the command '''&amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;'''.&lt;br /&gt;
* '''run''': running an IOC is the action of running the binary along with a startup script of iocsh commands (usually called '''&amp;lt;code&amp;gt;st.cmd&amp;lt;/code&amp;gt;''')&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: &lt;br /&gt;
* Any change in the build configuration ('''&amp;lt;span style=&amp;quot;color: orange&amp;quot;&amp;gt;Orange folders&amp;lt;/span&amp;gt;''') requires to recompile the IOC by issuing a '''&amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;'''. &lt;br /&gt;
* Any change in the runtime configuration ('''&amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt;Green folders&amp;lt;/span&amp;gt;''') requires to reboot the IOC.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:IOCtree.jpg|right|thumb|300px|xxx IOC tree]]&lt;br /&gt;
&lt;br /&gt;
=== Build configuration ===&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;span style=&amp;quot;color: orange&amp;quot;&amp;gt;Orange folders:&amp;lt;/span&amp;gt;'''&lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/configure&amp;lt;/code&amp;gt;''': &lt;br /&gt;
:contains the files that specify which versions of EPICS base and EPICS modules should be used when building the IOC.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/xxxApp/Db&amp;lt;/code&amp;gt;''': &lt;br /&gt;
:contains local databases (and associated autosave files) and protocol files used by the IOC.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/xxxApp/src&amp;lt;/code&amp;gt;''': &lt;br /&gt;
:contains the Makefile that determines all of the software that gets built into the IOC binary. ; local sequence programs and other EPICS support that needs to be compiled go here.&lt;br /&gt;
&lt;br /&gt;
=== Intermediate build directories ===&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;span style=&amp;quot;color: lightgrey&amp;quot;&amp;gt;Grey folders:&amp;lt;/span&amp;gt; &amp;lt;br&amp;gt;''' The EPICS build system will generate '''&amp;lt;code&amp;gt;O.&amp;lt;/code&amp;gt;''' files (Common, EPICS HOST and TARGET architectures) in the configure, Db, and src directories (orange directories).  These directories are not needed after the IOC is built and can be removed with the '''&amp;lt;code&amp;gt;make clean&amp;lt;/code&amp;gt;''' command. If they are not removed, they can be safely ignored.  It is highly unlikely that you will ever need to look at any of the files in them.&lt;br /&gt;
&lt;br /&gt;
=== Build products ===&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;span style=&amp;quot;color: red&amp;quot;&amp;gt;Red folders:&amp;lt;/span&amp;gt;'''&amp;lt;br&amp;gt; &lt;br /&gt;
The EPICS build system creates top level bin, db, dbd, and lib directories: &lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/bin/rehl8-x86_64&amp;lt;/code&amp;gt;''':&lt;br /&gt;
:contains the architecture-specific IOC binary (or munch file for VxWorks IOCs).  &lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/db&amp;lt;/code&amp;gt;''': &lt;br /&gt;
:contains installed database files which may or may not be used, since many IOCs reference the databases in the '''&amp;lt;code&amp;gt;Db&amp;lt;/code&amp;gt;''' directory instead.  &lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/dbd&amp;lt;/code&amp;gt;''': &lt;br /&gt;
:contains a single database definition file to be loaded by the IOC. &lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxx/lib/rehl8-x86_64&amp;lt;/code&amp;gt;''': &lt;br /&gt;
:contains architecture-specific files for EPICS modules, but should be empty for the IOC.&amp;lt;br&amp;gt;&lt;br /&gt;
The build system creates an '''&amp;lt;code&amp;gt;envPaths&amp;lt;/code&amp;gt;''' file in the startup directory '''&amp;lt;code&amp;gt;iocBoot/iocxxx&amp;lt;/code&amp;gt;''', which contains the locations of the modules defined in the '''&amp;lt;code&amp;gt;RELEASE&amp;lt;/code&amp;gt;''' file.&lt;br /&gt;
&lt;br /&gt;
=== Startup directory ===&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;span style=&amp;quot;color: green&amp;quot;&amp;gt;Green folders:&amp;lt;/span&amp;gt;'''  &amp;lt;br&amp;gt;&lt;br /&gt;
The '''&amp;lt;code&amp;gt;iocxxx&amp;lt;/code&amp;gt;''' directory is referred to as the '''startup''' directory.  It contains the '''&amp;lt;code&amp;gt;st.cmd&amp;lt;/code&amp;gt;''' file, which is the '''runtime configuration''' for the IOC (i.e. all the files the IOC needs to load to run/start).&lt;br /&gt;
The IOC’s config is often broken into separate '''&amp;lt;code&amp;gt;.iocsh&amp;lt;/code&amp;gt;''' (or '''&amp;lt;code&amp;gt;.cmd&amp;lt;/code&amp;gt;''') files so that support can be more easily commented out and to improve readability; '''&amp;lt;code&amp;gt;substitutions&amp;lt;/code&amp;gt;''' and '''&amp;lt;code&amp;gt;iocsh&amp;lt;/code&amp;gt;''' files usually reside in subdirectories to reduce clutter in the startup directory.&lt;br /&gt;
&lt;br /&gt;
=== Startup scripts ===&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;span style=&amp;quot;color: blue&amp;quot;&amp;gt;Blue folders:&amp;lt;/span&amp;gt;'''  &amp;lt;br&amp;gt;&lt;br /&gt;
The top-level IOC directory '''&amp;lt;code&amp;gt;xxx&amp;lt;/code&amp;gt;''' contains scripts that start medm &amp;amp; caQtDM.&lt;br /&gt;
The startup directory &amp;lt;code&amp;gt;'''softioc'''&amp;lt;/code&amp;gt; subdirectory contains a bash script which simplifies managing the IOC on Linux.&lt;br /&gt;
Windows IOCs: the startup directory contains batch files to start the IOC.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: The startup directory can reside elsewhere.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does support get into an IOC? ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Quick overview ===&lt;br /&gt;
&lt;br /&gt;
[[File:EPICS_basics_linking_diagrams.png|right|thumb|800px]]&lt;br /&gt;
* '''&amp;lt;code&amp;gt;configure/RELEASE&amp;lt;/code&amp;gt;''':&lt;br /&gt;
** Defines the locations of EPICS base and EPICS modules&lt;br /&gt;
** Often includes other RELEASE files&lt;br /&gt;
** '''&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: already included when using &amp;lt;code&amp;gt;mkioc&amp;lt;/code&amp;gt;'''&lt;br /&gt;
* '''&amp;lt;code&amp;gt;xxxApp/src/Makefile&amp;lt;/code&amp;gt;''':&lt;br /&gt;
** Specifies which database definitions ('''&amp;lt;code&amp;gt;dbd&amp;lt;/code&amp;gt;''') to include&lt;br /&gt;
** Specifies which libraries should be included in the IOC binary&lt;br /&gt;
** Specifies which local code should be included in the IOC binary&lt;br /&gt;
** Libraries will not be included unless an associated '''&amp;lt;code&amp;gt;dbd&amp;lt;/code&amp;gt;''' file is included&lt;br /&gt;
** The order of the libraries is important (single-pass linker)&lt;br /&gt;
** '''&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: unless you are adding a non-synApps module or an uncommon motor driver, you should not need to modify the &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt;'''&lt;br /&gt;
* '''&amp;lt;code&amp;gt;iocBoot/iocxxx/st.cmd&amp;lt;/code&amp;gt;''':&lt;br /&gt;
** That is the runtime configuration file, i.e. the primary IOC config file that is sourced when the IOC is started: determines all the things that gets loaded (e.g. ''I want 7 motor records, with these names, and this resolution, etc...'')&lt;br /&gt;
** Name can vary slightly based on how the IOC was created&lt;br /&gt;
** '''&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: this is the file that you will very likely modify'''&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Startup script &amp;lt;code&amp;gt;st.cmd&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Legacy IOCs often have monolithic '''&amp;lt;code&amp;gt;st.cmd&amp;lt;/code&amp;gt;''' files. Newer IOCs source more '''&amp;lt;code&amp;gt;.iocsh&amp;lt;/code&amp;gt;''' files from EPICS modules, which makes it easier to keep an IOC's config up-to-date.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt; envPaths&lt;br /&gt;
 &lt;br /&gt;
 dbLoadDatabase(&amp;quot;../../dbd/iocxxxLinux.dbd&amp;quot;)&lt;br /&gt;
 iocxxxLinux_registerRecordDeviceDriver(pdbbase)&lt;br /&gt;
 &lt;br /&gt;
 ### Databases are loaded&lt;br /&gt;
 ### Drivers are initialized/configured here&lt;br /&gt;
 &lt;br /&gt;
 iocInit&lt;br /&gt;
 &lt;br /&gt;
 ### Sequence programs &amp;amp; autosave are started here&lt;br /&gt;
 &lt;br /&gt;
 dbl &amp;gt; dbl-all.txt&lt;br /&gt;
 &lt;br /&gt;
 date&lt;br /&gt;
&lt;br /&gt;
We can break it up into 3 functional zones:&lt;br /&gt;
* '''Zone 1''' - before '''&amp;lt;code&amp;gt;dbLoadDatabase&amp;lt;/code&amp;gt;''':  it is usually dedicated to setting-up the environment (e.g. defines environment variables and paths to EPICS modules).&lt;br /&gt;
* '''Zone 2''' - after '''&amp;lt;code&amp;gt;dbLoadDatabase&amp;lt;/code&amp;gt;''' &amp;amp; before '''&amp;lt;code&amp;gt;iocInit&amp;lt;/code&amp;gt;''':  this is were most of the software is loaded (e.g. databases and substitutions template are loaded here, drivers are initialized and configured).&lt;br /&gt;
* '''Zone 3''' - after '''&amp;lt;code&amp;gt;iocInit&amp;lt;/code&amp;gt;''': this zone is mostly empty thanks to '''&amp;lt;code&amp;gt;doAfterIocInit&amp;lt;/code&amp;gt;''' from the '''&amp;lt;code&amp;gt;std&amp;lt;/code&amp;gt;''' module (sequence programs and autosave get initialized here, but the calls that do the initializing appear much earlier in the startup)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: PVs are available during '''&amp;lt;code&amp;gt;iocInit&amp;lt;/code&amp;gt;''', even though the IOC is still starting up.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Autosave ===&lt;br /&gt;
&lt;br /&gt;
'''autosave''' is a synApps module that provides seamless reboot functionality. It is mostly automatic when '''&amp;lt;code&amp;gt;mkioc&amp;lt;/code&amp;gt;''' is used. &lt;br /&gt;
PVs are saved while the IOC is running and loaded during '''&amp;lt;code&amp;gt;iocInit&amp;lt;/code&amp;gt;'''.  &lt;br /&gt;
Autosaved values overwrite database defaults.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:IOC_autosave.jpg|right|thumb|300px]]&lt;br /&gt;
&lt;br /&gt;
In ''xxx''-based IOCs, created using '''&amp;lt;code&amp;gt;mkioc&amp;lt;/code&amp;gt;''', autosave is included by default: '''&amp;lt;code&amp;gt;common.iocsh&amp;lt;/code&amp;gt;''' contains all the necessary configuration, and you will only need to modify it if you want to customize something. It also includes an '''autosaveBuild''' feature: every loaded database with associated req files ('''&amp;lt;code&amp;gt;_settings.req&amp;lt;/code&amp;gt;''') are automatically added to '''&amp;lt;code&amp;gt;autosave/built_position.req&amp;lt;/code&amp;gt;''' and '''&amp;lt;code&amp;gt;autosave/built_settings.req&amp;lt;/code&amp;gt;''', so long as they use the correct naming convention, i.e. the '''&amp;lt;code&amp;gt;_settings.req&amp;lt;/code&amp;gt;''' uses the same prefix as the database.&amp;lt;br&amp;gt;&lt;br /&gt;
The legacy request files, '''&amp;lt;code&amp;gt;autosave_position.req&amp;lt;/code&amp;gt;''' and '''&amp;lt;code&amp;gt;autosave_settings.req&amp;lt;/code&amp;gt;''' (that live outside the '''&amp;lt;code&amp;gt;autosave&amp;lt;/code&amp;gt;''' directory) are reserved for things added manually (often empty).&lt;br /&gt;
Multiple '''&amp;lt;code&amp;gt;.sav&amp;lt;/code&amp;gt;''' files can be created:&lt;br /&gt;
* Default:&lt;br /&gt;
** '''&amp;lt;code&amp;gt;.sav&amp;lt;/code&amp;gt;''' &amp;amp; '''&amp;lt;code&amp;gt;.savB&amp;lt;/code&amp;gt;'''&lt;br /&gt;
** actually restored when the IOC restarts&lt;br /&gt;
* Periodic:&lt;br /&gt;
** '''&amp;lt;code&amp;gt;.sav0&amp;lt;/code&amp;gt;''', '''&amp;lt;code&amp;gt;.sav1&amp;lt;/code&amp;gt;''', '''&amp;lt;code&amp;gt;.sav2&amp;lt;/code&amp;gt;''', …&lt;br /&gt;
** overwritten cyclically; if the default one do not exist, those ones get restored. &lt;br /&gt;
* Dated:&lt;br /&gt;
** '''&amp;lt;code&amp;gt;.sav-230109-134502&amp;lt;/code&amp;gt;'''&lt;br /&gt;
** written once at boot time&lt;br /&gt;
&lt;br /&gt;
The 1st half of '''&amp;lt;code&amp;gt;common.iocsh&amp;lt;/code&amp;gt;''' sets up autosave:&lt;br /&gt;
[https://github.com/epics-modules/xxx/blob/master/iocBoot/iocxxx/common.iocsh#L1-L46 https://github.com/epics-modules/xxx/blob/master/iocBoot/iocxxx/common.iocsh#L1-L46]&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== How to build &amp;amp; clean a Linux IOC ===&lt;br /&gt;
&lt;br /&gt;
* Confirm the RHEL version&lt;br /&gt;
** &amp;lt;code&amp;gt; '''uname -r''' → 3.10.0-1160.62.1.'''el7'''.x86_64&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt; '''cat /etc/redhat-release''' → Red Hat Enterprise Linux Server release '''7.9'''&amp;lt;/code&amp;gt;&lt;br /&gt;
* Set &amp;lt;code&amp;gt; EPICS_HOST_ARCH&amp;lt;/code&amp;gt;  environment variable&lt;br /&gt;
** bash: &amp;lt;code&amp;gt;'''export EPICS_HOST_ARCH=rhel7-x86_64'''&amp;lt;/code&amp;gt;&lt;br /&gt;
** tcsh: &amp;lt;code&amp;gt;'''setenv EPICS_HOST_ARCH rhel7-x86_64'''&amp;lt;/code&amp;gt;&lt;br /&gt;
* Initiate the build in the top-level IOC directory:&lt;br /&gt;
** &amp;lt;code&amp;gt;'''make'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Remove intermediate build dirs (for the current &amp;lt;code&amp;gt; EPICS_HOST_ARCH&amp;lt;/code&amp;gt;):&lt;br /&gt;
** &amp;lt;code&amp;gt;'''make clean'''&amp;lt;/code&amp;gt; &lt;br /&gt;
* Remove all intermediate build dirs and top-level build directories to start fresh:&lt;br /&gt;
** &amp;lt;code&amp;gt;'''make distclean'''&amp;lt;/code&amp;gt;&lt;br /&gt;
* Show all make options:&lt;br /&gt;
** &amp;lt;code&amp;gt;'''make help'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Running an IOC ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Use the script ===&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==== Create an alias ====&lt;br /&gt;
&lt;br /&gt;
Create an alias for the script (assuming PWD = IOC’s top-level dir)&lt;br /&gt;
:&amp;lt;code&amp;gt;$ '''alias kmp=${PWD}/iocBoot/iockmp/softioc/kmp.sh'''&amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;$ '''kmp''' &amp;lt;/code&amp;gt;&lt;br /&gt;
:&amp;lt;code&amp;gt;Usage: kmp.sh {console|restart|run|start|caqtdm|medm|status|stop|usage}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Noteworthy arguments:&lt;br /&gt;
* '''&amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt;''': Runs the IOC in the current terminal (doesn't return the command prompt). Useful for troubleshooting.  Problematic for normal operation.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt;''': Runs the IOC in the background (returns the command prompt) using screen or procServ.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt;''': Tells you if the IOC is running and refuses to start if it is.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: &lt;br /&gt;
* Use the full path to the IOC’s start script so the alias can be run from any directory (bash syntax shown).&lt;br /&gt;
* &amp;lt;code&amp;gt;EPICS_HOST_ARCH&amp;lt;/code&amp;gt; needs to still be set otherwise the IOC will not start (unless the &amp;lt;code&amp;gt;EPICS_HOST_ARCH&amp;lt;/code&amp;gt; is hard-coded in the start script).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Start caQtDM ====&lt;br /&gt;
&lt;br /&gt;
:'''&amp;lt;code&amp;gt;kmp caqtdm &amp;amp;&amp;lt;/code&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: the ampersand is needed for synApps_6_2_1 IOCs, but it won’t be needed in the future because it was added to the '''&amp;lt;code&amp;gt;start_caQtDM_xxx&amp;lt;/code&amp;gt;''' script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Start the IOC ====&lt;br /&gt;
&lt;br /&gt;
Starts the IOC in the background (using screen or procServ):&lt;br /&gt;
&lt;br /&gt;
:'''&amp;lt;code&amp;gt;kmp start&amp;lt;/code&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
IOCs are usually run in screen or procServ so that: &lt;br /&gt;
* the window in which they’re started can be closed&lt;br /&gt;
* multiple people can connect to them&lt;br /&gt;
* [procServ] allows other user accounts to restart an IOC&lt;br /&gt;
* [procServ] allows users to connect to Windows IOCs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Confirm the IOC is running ====&lt;br /&gt;
&lt;br /&gt;
:'''&amp;lt;code&amp;gt;kmp status&amp;lt;/code&amp;gt;'''&lt;br /&gt;
:&amp;lt;code&amp;gt;kmp is running (pid=1281733) in a screen session (pid=1281732)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: bugs in the deployed copy of '''&amp;lt;code&amp;gt;xxx.sh&amp;lt;/code&amp;gt;''' may prevent it from detecting an IOC is running.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Connecting to an IOC’s shell ===&lt;br /&gt;
&lt;br /&gt;
There are many ways to do it:&lt;br /&gt;
&lt;br /&gt;
* Manually connect to an IOC running in screen from the IOC’s host&lt;br /&gt;
::&amp;lt;code&amp;gt;$ '''screen -x kmp'''&amp;lt;/code&amp;gt;&lt;br /&gt;
::The -x option will connect even if someone is already connected to the screen session.  &lt;br /&gt;
::The -r option only succeeds if no one is connected to the session.&lt;br /&gt;
&lt;br /&gt;
* Connect to an IOC running in screen or procServ from the IOC’s host&lt;br /&gt;
::&amp;lt;code&amp;gt;$ '''kmp console'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Connect to an IOC running in screen or procServ with logging '''from any host'''&lt;br /&gt;
::&amp;lt;code&amp;gt;$ '''/APSshare/bin/iocConsole.py iockmp'''&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;u&amp;gt;Note&amp;lt;/u&amp;gt;: iocConsole.py requires ssh access which beamline accounts don't have by default&lt;br /&gt;
&lt;br /&gt;
* Manually connect to an IOC running in procServ from the IOC’s subnet&lt;br /&gt;
::&amp;lt;code&amp;gt;$ '''telnet s100bcda 53127'''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Disconnecting from an IOC’s shell ===&lt;br /&gt;
&lt;br /&gt;
* '''Close the terminal''' that is connected to the screen or procServ session&lt;br /&gt;
** Disconnects from both screen &amp;amp; procServ&lt;br /&gt;
** Kills an IOC running outside of screen &amp;amp; procServ&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Ctrl+a&amp;lt;/code&amp;gt;''', '''&amp;lt;code&amp;gt;Ctrl+d&amp;lt;/code&amp;gt;'''&lt;br /&gt;
** Disconnects from both screen &amp;amp; procServ&lt;br /&gt;
** Kills an IOC running outside of screen &amp;amp; procServ&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Ctrl+a, d&amp;lt;/code&amp;gt;'''&lt;br /&gt;
** Only disconnects from screen&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== IOC shell commands ===&lt;br /&gt;
&lt;br /&gt;
See [https://wiki-ext.aps.anl.gov/blc/index.php?title=EPICS_Cheat_Sheet EPICS Cheat Sheet]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Where does EPICS support reside at the APS ==&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:IOC_Support.jpg|center|thumb|500px]]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What's next? ==&lt;br /&gt;
For step by step instructions to create your own IOC, go to [https://git.aps.anl.gov/practical_beamline_controls_training/session_2/instructions IOC Deployment &amp;amp; Troubleshooting].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=736</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=736"/>
		<updated>2023-12-01T17:33:36Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Your branch and 'origin/main' have diverged */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** For more info on addressing conflict, see [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=735</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=735"/>
		<updated>2023-12-01T17:32:46Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Your branch and 'origin/main' have diverged */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have '''diverged'''. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=734</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=734"/>
		<updated>2023-12-01T17:32:08Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Your branch is ahead of 'origin/main' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''ahead''' of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=733</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=733"/>
		<updated>2023-12-01T17:31:57Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Your branch is behind 'origin/main' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is '''behind''' &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the ''remote'' repository that you don't have ''locally''.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=732</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=732"/>
		<updated>2023-12-01T17:31:13Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Your branch is ahead of 'origin/main' */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits ''locally'' that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the ''remote'' repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=731</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=731"/>
		<updated>2023-12-01T17:28:51Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Typical Branching Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch ''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=730</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=730"/>
		<updated>2023-12-01T17:21:37Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Git Workflow Components */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the ''local'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the ''remote'' &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=729</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=729"/>
		<updated>2023-12-01T17:21:09Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Git Workflow Components */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name it &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=728</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=728"/>
		<updated>2023-12-01T16:58:47Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes, in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit, in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (merging) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; = &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the '''upstream''' for your branch.&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; the changes from / to.&lt;br /&gt;
* To resolve this, you can either set the upstream branch as suggested in the error message, or '''specify the remote name and branch''' (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) '''every time''' you &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;/ &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To specify the remote &amp;amp; branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Or to set the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=727</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=727"/>
		<updated>2023-12-01T16:38:58Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Branching for IOCs Upgrade */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main                                # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch                                        # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                                         # Pull (= fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1                      # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1                   # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
You are now ready to upgrade the &amp;lt;code&amp;gt;synApps_6_2/ioc&amp;lt;/code&amp;gt; directory from &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/synApps_6_1&amp;lt;/code&amp;gt;).&lt;br /&gt;
* In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch (associated to the remote branch &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=726</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=726"/>
		<updated>2023-12-01T16:33:55Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Version Control for EPICS IOCs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from .gitattributes xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from .gitignore xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' very important '''Uncheck initialize repository'''   (to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git               # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                                          # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                                # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=725</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=725"/>
		<updated>2023-12-01T16:31:32Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commit Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101#Upstream_Branch Upstream Branch].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=724</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=724"/>
		<updated>2023-12-01T16:30:48Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commit Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git status              # Check the status of your local repo&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit a new file:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes at once:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=723</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=723"/>
		<updated>2023-11-29T21:28:26Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commit Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=722</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=722"/>
		<updated>2023-11-29T21:28:21Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commit Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:.&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=721</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=721"/>
		<updated>2023-11-29T21:28:07Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commit Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=720</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=720"/>
		<updated>2023-11-29T21:28:01Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Basic Commit Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:.&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=719</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=719"/>
		<updated>2023-11-29T21:27:17Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Upstream Branch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=718</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=718"/>
		<updated>2023-11-29T21:27:09Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Upstream Branch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below)..&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
	<entry>
		<id>https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=717</id>
		<title>Git 101</title>
		<link rel="alternate" type="text/html" href="https://wiki-ext.aps.anl.gov/blc/index.php?title=Git_101&amp;diff=717"/>
		<updated>2023-11-29T21:26:53Z</updated>

		<summary type="html">&lt;p&gt;Rodolakis: /* Upstream Branch */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Practical Step-by-Step Examples ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Commit Workflow ===&lt;br /&gt;
&lt;br /&gt;
This &amp;lt;code&amp;gt;(pull-)edit-add-commit(-push)&amp;lt;/code&amp;gt; recipe is all you need for 95% of projects:&lt;br /&gt;
&lt;br /&gt;
* To sync your local repository with the remote repository:&lt;br /&gt;
 $ git checkout main       # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                # Pull the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* To commit new files:&lt;br /&gt;
 $ git add &amp;amp;lt;newfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Added &amp;amp;lt;newfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit changes to an existing file:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;&lt;br /&gt;
 $ git commit -m 'Updated &amp;amp;lt;modifiedfile&amp;amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* To commit all changes:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git commit -am 'Description of changes'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push your changes to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt; $ git push&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' This workflow assumes you are working with the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch, and that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; has been set as the [[Upstream Branch]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Version Control for EPICS IOCs ===&lt;br /&gt;
&lt;br /&gt;
Initialize the local repository:&lt;br /&gt;
&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitattributes .   # copy from xxx&lt;br /&gt;
 $ cp /APSshare/epics/synApps_6_2_1/support/xxx-R6-2-1/.gitignore .       # copy from xxx&lt;br /&gt;
 $ git init                                                               # initialize repo&lt;br /&gt;
 $ git add .                                                              # stage all relevant stuff&lt;br /&gt;
 $ git status                                                             # confirm status&lt;br /&gt;
 $ git commit -m 'first commit yeah!'                                     # commit all staged files&lt;br /&gt;
&lt;br /&gt;
On GitLab, in the corresponding beamline group:&lt;br /&gt;
&lt;br /&gt;
* '''New project''' (blue button, upper right corner)&lt;br /&gt;
* '''Create blank project'''&lt;br /&gt;
* '''Project name:''' myioc       (same spelling as IOC prefix)&lt;br /&gt;
* '''Project slug:''' myioc       (needs to be the same as project name)&lt;br /&gt;
* '''Visibility Level:''' Internal&lt;br /&gt;
* '''Project Configuration:''' '''Uncheck initialize repository'''   (very important to avoid conflict between local and remote)&lt;br /&gt;
* '''Create project'''&lt;br /&gt;
* '''Clone drop-down''' (blue button, right hand-side): copy the '''SSH''' remote URL &amp;lt;code&amp;gt;git@git.aps.anl.gov:29id/myioc.git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the local repository, add the reference to the new remote repository:&lt;br /&gt;
&lt;br /&gt;
 $ git remote add origin git@git.aps.anl.gov:29id/myioc.git  # adds a new remote repository named origin with the given URL)&lt;br /&gt;
 $ git remote -v                                             # lists remote connections to confirm the addition&lt;br /&gt;
 $ git push -u origin main                                   # pushes main to the origin remote and sets it as the upstream&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Branching for IOCs Upgrade ===&lt;br /&gt;
&lt;br /&gt;
* Make sure your local repository in &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; is up-to-date:&lt;br /&gt;
 $ git checkout main       # Make sure your are on the main branch&lt;br /&gt;
 $ git fetch               # Fetch the latest changes from the remote&lt;br /&gt;
 $ git pull                # Pull (fetch + merge) the latest changes from the remote&lt;br /&gt;
&lt;br /&gt;
* Create and switch to a new branch named &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; (for archive purposes)&lt;br /&gt;
 $ git checkout -b synApps_6_1        # Create a new branch based on main and switch to it&lt;br /&gt;
 $ git push -u origin synApps_6_1     # Push the new branch to the remote and set origin/synApps_6_1 as the upstream for this branch&lt;br /&gt;
&lt;br /&gt;
* Clone the IOC repository into the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
 $ cd ../../../synApps_6_2/ioc/                     # Navigate to the synApps_6_2/ioc directory&lt;br /&gt;
 $ git clone git@git.aps.anl.gov:29id/myioc.git     # Clone the repository&lt;br /&gt;
&lt;br /&gt;
*'''Note:''' the new &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch now points to the &amp;lt;code&amp;gt;synApps_6_2&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_1/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;synApps_6_1&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
** In the directory &amp;lt;code&amp;gt;synApps_6_2/ioc/myioc&amp;lt;/code&amp;gt;, you will be working on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Commands ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Viewing Changes and Status ===&lt;br /&gt;
* To switch to the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git checkout main&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see the status of the working directory and staging area (also confirm the current branch you are on):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git status&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To list the commit history:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git log&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To view differences since the last commit:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git diff &amp;amp;lt;file&amp;amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
* To see tracked files:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git ls-files&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Committing Changes ===&lt;br /&gt;
* To commit a single tracked file (add file to staging area and commit changes in two steps):&lt;br /&gt;
 $ git add &amp;amp;lt;file&amp;amp;gt;  &lt;br /&gt;
 $ git commit -m 'commit message'  &lt;br /&gt;
&lt;br /&gt;
* To commit all tracked files at once, use option &amp;lt;code&amp;gt;-a&amp;lt;/code&amp;gt; (add to staging area and commit in a single step):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git commit -am 'commit message'  &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ignoring Files ===&lt;br /&gt;
&amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; lists files and folders to be ignored. To update the list, just use any file editor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Syncing with Remote Repository ===&lt;br /&gt;
* To download updates from the remote repository without merging them:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git fetch          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To fetch changes from the remote repository and merge them into your current branch:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git pull            &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To push local commits to the remote repository:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git push          &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To list the remote repositories and their URLs:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ git remote -v    &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Upstream Branch ===&lt;br /&gt;
&lt;br /&gt;
* The instructions provided in here assume that &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch of the remote repository) is already set as the upstream for your branch (more info below).&lt;br /&gt;
* If an upstream branch has not been set, you will encounter errors when attempting to &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt;:&lt;br /&gt;
 fatal: The current branch has no upstream branch.&lt;br /&gt;
 To push the current branch and set the remote as upstream, use&lt;br /&gt;
 &lt;br /&gt;
     git push --set-upstream origin &amp;lt;branch_name&amp;gt;&lt;br /&gt;
* This message is Git's way of telling you that it does not know where to fetch/pull/push the changes from/to.&lt;br /&gt;
* To resolve this, you either set the upstream branch as suggested or specify the remote name and branch (typically &amp;lt;code&amp;gt;origin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;, respectively) every time you pull or push.&lt;br /&gt;
** For setting the upstream, you would use: &amp;lt;code&amp;gt;$ git push -u origin &amp;lt;branch_name&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
** Or specify the remote and branch name:  &amp;lt;code&amp;gt;$ git fetch/pull/push origin &amp;lt;branch_name&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;-u&amp;lt;/code&amp;gt; flag stands for &amp;lt;code&amp;gt;--set-upstream&amp;lt;/code&amp;gt;:&lt;br /&gt;
** This flag is used to set a relationship between your local branch and a remote branch: &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; is now the upstream for your current local branch.&lt;br /&gt;
** Once the upstream is set, you can use &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;fetch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; '''without specifying the remote name and branch'''. Git will automatically know that you're referring to &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Git Fetch vs. Git Pull ===&lt;br /&gt;
* &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt;: '''downloads''' changes from a remote repository, but '''doesn't integrate any of these changes''' into your working files. It's essentially a '''safe way to review changes''' before integrating (pulling) them into your local repository.&lt;br /&gt;
* &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;: not only '''downloads''' changes from the remote repository but also immediately attempts to '''merge''' them into the branch you are currently working on:&amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt; =  &amp;lt;code&amp;gt;git fetch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git merge&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Custom aliases ===&lt;br /&gt;
&lt;br /&gt;
 $ git config --global alias.st 'status'         # create an alias git st = git status&lt;br /&gt;
 $ git config --global --list                    # see list of aliases&lt;br /&gt;
 $ git config --global --replace-all alias.lg    # may need replace-all flag&lt;br /&gt;
                                                 # to overwrite existing aliases&lt;br /&gt;
 #### Common aliases:  &lt;br /&gt;
 $ alias.br 'branch'&lt;br /&gt;
 $ alias.ci 'commit'&lt;br /&gt;
 $ alias.co 'checkout'&lt;br /&gt;
 $ alias.st 'status'&lt;br /&gt;
 $ alias.df 'diff'&lt;br /&gt;
 $ alias.ft 'fetch'&lt;br /&gt;
 $ alias.lg &amp;quot;log -10 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&amp;lt;%an&amp;gt;%Creset' --abbrev-commit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This last command sets a global alias &amp;lt;code&amp;gt;lg&amp;lt;/code&amp;gt; for git, which transforms the output of git log into a visually structured and color-coded format, displaying the last 10 commits.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git Workflow Components ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:git_101.jpg|thumb|center|900px]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* '''Working Directory''': Your local workspace where you edit files. Changes here are not tracked until moved to the staging area.&lt;br /&gt;
* '''Staging Area''': A prep zone for changes to be committed. You can selectively choose which changes to include in a commit.&lt;br /&gt;
* '''HEAD''': The latest commit in the current branch, acting as a pointer to your most recent work.&lt;br /&gt;
* '''Local Repository''': Your computer's storage for all your commits, branches, and the entire change history. It operates independently of network access.&lt;br /&gt;
* '''Remote Repository''': A server-hosted repository (e.g., GitLab, GitHub) for code sharing and backup. It syncs with the local repository through &amp;lt;code&amp;gt;push&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pull&amp;lt;/code&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For the longest time, the default branch in most Git repositories was named &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt;; the convention is now to name is &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. To rename the local &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;$ git branch -m master main&amp;lt;/code&amp;gt;        &lt;br /&gt;
&lt;br /&gt;
To rename the remote &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch, see [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Git File Status ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Tracked vs Untracked Files ===&lt;br /&gt;
* '''Tracked''' files are those that Git knows about and has in its version history.&lt;br /&gt;
* '''Untracked''' files are new or unrecorded files in your working directory that Git isn't keeping track of yet; e.g. &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_settings.sav*&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;auto_positions.sav*&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Staged vs Unstaged ===&lt;br /&gt;
* '''Staged''' files are those that have been marked for inclusion in the next commit, showing Git exactly what changes you want to commit.&lt;br /&gt;
* '''Unstaged''' files are the modified files in your working directory that have not been marked for the next commit yet.&lt;br /&gt;
* '''Why stage?''' Staging in Git is the process of selecting specific changes you want to include in your next commit. Instead of committing all the changes you've made since the last commit, you can choose a subset of these changes to commit.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git add ===&lt;br /&gt;
The &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; command is used for both staging changes and beginning to track new files:&lt;br /&gt;
* '''Staging Changes''': When you modify a file that is already being tracked by Git (i.e., it's been committed at least once before), using &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; stages these changes. This means you're marking the modifications in that file to be included in the next commit.&lt;br /&gt;
* '''Tracking New Files''': For new files that are not yet tracked by Git (they have never been committed), &amp;lt;code&amp;gt;git add &amp;lt;filename&amp;gt;&amp;lt;/code&amp;gt; starts tracking these files in addition to staging them. From this point onward, any changes to these files will be recognized by Git.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Branching Basics ==&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Git_branching.jpg|thumb|center|600px]]&lt;br /&gt;
&lt;br /&gt;
=== Branching Overview ===&lt;br /&gt;
&lt;br /&gt;
* '''What is a Branch?'''&lt;br /&gt;
It's essentially a separate line of development. You can think of it as an independent line of work that doesn't interfere with others.&lt;br /&gt;
&lt;br /&gt;
* '''Why Use Branches?'''&lt;br /&gt;
They allow you to work on new features, bug fixes, or experiments in isolation from the main (deployed) code.&lt;br /&gt;
Branches facilitate parallel development, enabling multiple team members to work on different aspects simultaneously without stepping on each other's toes.&lt;br /&gt;
&lt;br /&gt;
* '''How Does it Work?:'''&lt;br /&gt;
When you create a branch in Git, you're creating a new pointer to commits.&lt;br /&gt;
It's like a bookmark on your work, allowing you to switch contexts quickly.&lt;br /&gt;
Changes made in a branch don't affect other branches. You can merge these changes back into the main branch when they're ready.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Typical Branching Workflow ===&lt;br /&gt;
&lt;br /&gt;
* Create a new branch from the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch:&lt;br /&gt;
 $ git checkout main           # Switch to (or confirm you are on) the main branch&lt;br /&gt;
 $ git pull                    # Ensure it's up to date with the remote&lt;br /&gt;
 $ git checkout -b new-branch  # Create a new branch and switch to it&lt;br /&gt;
Note that because of the &amp;lt;code&amp;gt;-b&amp;lt;/code&amp;gt; option in &amp;lt;code&amp;gt;git checkout -b new-branch&amp;lt;/code&amp;gt;, this command is equivalent to &amp;lt;code&amp;gt;git branch new-branch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;git checkout new-branch&amp;lt;/code&amp;gt;, i.e. create a branch '''and'' switch to it.&lt;br /&gt;
&lt;br /&gt;
* Make your changes in this new branch and test them to ensure they work as intended.&lt;br /&gt;
* Add and commit your changes:&lt;br /&gt;
 $ git add &amp;amp;lt;modifiedfile&amp;amp;gt;      &lt;br /&gt;
 $ git commit -m &amp;quot;Your commit message&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Merge the branch back into &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; once your work is complete:&lt;br /&gt;
 $ git checkout main           # Switch back to the main branch&lt;br /&gt;
 $ git pull                    # Update the main branch (just in case)&lt;br /&gt;
 $ git merge new-branch        # Merge the new branch into main&lt;br /&gt;
 $ git push                    # Push the updates to the remote repository&lt;br /&gt;
&lt;br /&gt;
This workflow assumes you're starting from and merging back into a branch named &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;. Replace main with the appropriate branch name if different in your repository.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== Git Status Explained - General Case ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is up to date with 'origin/main'.&lt;br /&gt;
 &lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
   (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file1&lt;br /&gt;
         new file:   file2&lt;br /&gt;
 &lt;br /&gt;
 Changes not staged for commit:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)&lt;br /&gt;
   (use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)&lt;br /&gt;
 &lt;br /&gt;
         modified:   file3&lt;br /&gt;
 &lt;br /&gt;
 Untracked files:&lt;br /&gt;
   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)&lt;br /&gt;
 &lt;br /&gt;
         temp/&lt;br /&gt;
         notes.txt&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''': Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is up to date with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; (the main branch from the remote repository).&lt;br /&gt;
* '''Changes to be Committed''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file1&amp;lt;/code&amp;gt; has been modified and &amp;lt;code&amp;gt;file2&amp;lt;/code&amp;gt; is a new file, both staged for the next commit.&lt;br /&gt;
** To unstage, use &amp;lt;code&amp;gt;git reset HEAD &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Changes Not Staged for Commit''':&lt;br /&gt;
** &amp;lt;code&amp;gt;file3&amp;lt;/code&amp;gt; is modified but not staged.&lt;br /&gt;
** To stage, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To discard changes, use &amp;lt;code&amp;gt;git checkout -- &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Untracked Files''':&lt;br /&gt;
** &amp;lt;code&amp;gt;temp/&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;notes.txt&amp;lt;/code&amp;gt; are not tracked by Git.&lt;br /&gt;
** To track, use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
** To ignore, add them to the &amp;lt;code&amp;gt;.gitignore&amp;lt;/code&amp;gt; file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is ahead of 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is ahead of 'origin/main' by 3 commits.&lt;br /&gt;
   (use &amp;quot;git push&amp;quot; to publish your local commits)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is ahead of &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 3 commits. This means you have made commits locally that are not yet in the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch on the remote repository.&lt;br /&gt;
** To synchronize these changes with the remote repository, use &amp;lt;code&amp;gt;git push&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch is behind 'origin/main' ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to update your local branch)&lt;br /&gt;
 &lt;br /&gt;
 nothing to commit, working tree clean&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Status''':&lt;br /&gt;
** Your &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch is behind &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; by 2 commits. This indicates that there are updates on the remote repository that you don't have locally.&lt;br /&gt;
** You can fast-forward your local branch to catch up with &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;git pull&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Your working directory is clean, meaning there are no unstaged changes or untracked files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Your branch and 'origin/main' have diverged ===&lt;br /&gt;
&lt;br /&gt;
 $ git status&lt;br /&gt;
 On branch main&lt;br /&gt;
 Your branch and 'origin/main' have diverged,&lt;br /&gt;
 and have 1 and 2 different commits each, respectively.&lt;br /&gt;
   (use &amp;quot;git pull&amp;quot; to merge the remote branch into yours)&lt;br /&gt;
 &lt;br /&gt;
 You have unmerged paths.&lt;br /&gt;
   (fix conflicts and run &amp;quot;git commit&amp;quot;)&lt;br /&gt;
   (use &amp;quot;git merge --abort&amp;quot; to abort the merge)&lt;br /&gt;
 &lt;br /&gt;
 Unmerged paths:&lt;br /&gt;
   (use &amp;quot;git add &amp;amp;lt;file&amp;amp;gt;...&amp;quot; to mark resolution)&lt;br /&gt;
         both modified:   conflicted_file.txt&lt;br /&gt;
 &lt;br /&gt;
 no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
* '''On Branch''': You're currently on the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch.&lt;br /&gt;
* '''Branch Divergence''':&lt;br /&gt;
** Your local &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; branch and remote &amp;lt;code&amp;gt;origin/main&amp;lt;/code&amp;gt; branch have diverged. This means there are different commits in both branches that are not in the other.&lt;br /&gt;
* '''Merge Conflict''':&lt;br /&gt;
** A merge conflict has occurred in &amp;lt;code&amp;gt;conflicted_file.txt&amp;lt;/code&amp;gt; due to differing changes from both the local and remote branches.&lt;br /&gt;
** To resolve the merge conflict, manually edit the file to reconcile the differences, then use &amp;lt;code&amp;gt;git add &amp;amp;lt;file&amp;amp;gt;&amp;lt;/code&amp;gt; to mark the conflict as resolved.&lt;br /&gt;
** After resolving the conflict, complete the merge by committing the changes with &amp;lt;code&amp;gt;git commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
** If you wish to cancel the merge, use &amp;lt;code&amp;gt;git merge --abort&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Working Tree Status''':&lt;br /&gt;
** Address the merge conflict before proceeding with other Git operations.&lt;br /&gt;
** More info [https://www.atlassian.com/git/tutorials/using-branches/merge-conflicts here].&lt;/div&gt;</summary>
		<author><name>Rodolakis</name></author>
	</entry>
</feed>